home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / crc.swg / 0001_16BITCRC Routines.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  671b  |  35 lines

  1. {
  2. >I'm looking For code to calculate the CRC32 of a series of Characters.
  3.  
  4.   ...Unless you're CRCing a very large amount of data, this CRC-16
  5.   routine should do.
  6.  
  7.   NOTE: This routine requires either TP6 or TP7 to compile.
  8. }
  9.  
  10. { Return a 16-bit CRC number For binary data. }
  11.  
  12. Function Crc16(Var Data; wo_Size : Word) : Word; Assembler;
  13. Asm
  14.   push   ds
  15.   xor    dx, dx
  16.   lds    si, Data
  17.   mov    bx, wo_Size
  18. @L1:
  19.   xor    ah, ah
  20.   lodsb
  21.   mov    cx, 8
  22.   shl    ax, cl
  23.   xor    dx, ax
  24.   mov    cx, 8
  25. @L2:
  26.   shl    dx, 1
  27.   jnc    @L3
  28.   xor    dx, $1021
  29. @L3:
  30.   loop   @L2
  31.   dec    bx
  32.   jnz    @L1
  33.   pop    ds
  34.   mov    ax, dx
  35. end; { Crc16. }